﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CompareIndexKeyStructure.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   The compare index key structure.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.Common.Comparer
{
    using System;
    using System.Data;
    using DataAccess;
    using Helper;
    using Model;

    /// <summary>
    /// The compare index key structure.
    /// </summary>
    public class CompareIndexKeyStructure : CompareDataStructure
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CompareIndexKeyStructure"/> class. 
        /// The compare index key structure.
        /// </summary>
        /// <param name="databaseCompare">
        /// Compare object
        /// </param>
        /// <param name="objectType">
        /// Object type
        /// </param>
        public CompareIndexKeyStructure(DatabaseCompare databaseCompare, DatabaseObjectTypes objectType)
            : base(databaseCompare, objectType)
        {
            this.dv1Name = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.IndexKeyByTableName);
            this.dv1Key = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.IndexKeyByKey);
            this.dv2Name = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.IndexKeyByTableName);
            this.dv2Key = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.IndexKeyByKey);

            this.rowColumnName = DataRowCompareIndex.IndexKey;
        }

        /// <summary>
        /// The compare.
        /// </summary>
        /// <param name="currentIndexName">
        /// The index name.
        /// </param>
        /// <returns>
        /// The compare message
        /// </returns>
        public virtual string Compare(string currentIndexName)
        {
            this.indexName = currentIndexName;

            return base.Compare();
        }

        /// <summary>
        /// Compare NOT IMPLEMENTED
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        /// <returns>
        /// The compare.
        /// </returns>
        public override string Compare()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Find Index keys
        /// </summary>
        /// <param name="dv">
        /// Dataview for sorting
        /// </param>
        /// <param name="sort">
        /// Sort when true
        /// </param>
        /// <returns>
        /// The sorted datarowview
        /// </returns>
        protected override DataRowView[] FindRows(DataViewDs dv, bool sort)
        {
            var obj = new[] { this.cmp.CurrentOwner, this.cmp.CurrentName, this.indexName };
            return dv.FindRows(obj, sort);
        }
    }
}